package com.test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class JsonTool {
	public static void main(String[] args){
		testObj();
//		testList();
	}
	public static void testObj(){
		User user = new User();
	
		JsonWriter w = new JsonWriter();
		//global ,empty
		w.ctx.scops.push(new Scope());
		// data to render
	
		//data policy
		w.ctx.scops.push(new Scope());		
		PathRuleNode node = new PathRuleNode("id");
		node.setAction(new IgnoreAction());		
		w.ctx.scops.peek().addRuleNode(node);

		Item item = ItemFactory.create(null, user.getClass(), user);
		w.ctx.stack.push(item);
		
		RenderStack stack = w.ctx.stack;
		while(true){
			if(stack.isEmpty())break;
			Item it = (Item)stack.peek();
			it.render(w);
		}
		
	}
	public static void testList(){
		List list = Arrays.asList(1,2);
		Item item = ItemFactory.create(null, list.getClass(), list);		
		
	
		JsonWriter w = new JsonWriter();
		
		w.ctx.stack.push(item);
		w.ctx.scops.push(new Scope());
		
		
		ThisRuleNode rule0 = new ThisRuleNode();
		Set set = new HashSet();
		set.add(1);
		IncludeAction action = new IncludeAction(set);
		rule0.setAction(action);
		w.ctx.scops.peek().addRuleNode(rule0);
		
		RenderStack stack = w.ctx.stack;
		while(true){
			if(stack.isEmpty())break;
			Item it = (Item)stack.peek();
			it.render(w);
		}
	}
}
